package baiwa.rta.dao.mapping;

import baiwa.rta.model.RMaccrModel;
import baiwa.rta.model.TowerModel;

import java.sql.ResultSet;
import java.sql.SQLException;

import org.springframework.dao.DataAccessException;
import org.springframework.jdbc.core.ResultSetExtractor;
import org.springframework.jdbc.core.RowMapper;


public class CarCardMapping implements RowMapper<RMaccrModel> {

    public RMaccrModel mapRow(ResultSet rs, int line) throws SQLException {
        ResultSetExtractor<RMaccrModel> extractor = new ResultSetExtractor<RMaccrModel>() {
            public RMaccrModel extractData(ResultSet rs) throws SQLException, DataAccessException {
                RMaccrModel model = new RMaccrModel();
                model.setAccrid(rs.getInt("ACCRID"));
                model.setRlrmid(rs.getInt("RLRMID"));
                model.setAccrlrno(rs.getString("ACCRLRNO"));
                model.setAccrcrdid(rs.getString("ACCRCRDID"));
                model.setAccridusrno(rs.getString("ACCRIDUSRNO"));
                model.setAccrstat(rs.getString("ACCRSTAT"));
                model.setAccrstatdat(rs.getDate("ACCRSTATDAT"));
                model.setAccratvdat(rs.getDate("ACCRATVDAT"));
                model.setAccrcreby(rs.getString("ACCRCREBY"));
                model.setAccrcredat(rs.getDate("ACCRCREDAT"));
                model.setAccrupdby(rs.getString("ACCRUPDBY"));
                model.setAccrupddat(rs.getDate("ACCRUPDDAT"));
                
                /* ---- Tower Data From Join Table------*/
                TowerModel tower = new TowerModel();
                tower.setTower(rs.getString("RLSTTOWER"));
                tower.setFloor(rs.getString("RLSTFLOOR"));
                tower.setUnitNo(rs.getString("RLSTUNITNO"));
                tower.setAddress(rs.getString("RLSTADDR"));
                model.setTower(tower);
                
                return model;
            }
        };
        return extractor.extractData(rs);
    }
}
